package com.herui.ota.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.herui.ota.config.ControllerNames;
import com.herui.ota.entity.DeviceOta;
import com.herui.ota.entity.DeviceOtaConfig;
import com.herui.ota.pojo.form.DeviceFilterForm;
import com.herui.ota.pojo.form.DeviceOtaFilterForm;
import com.herui.ota.pojo.form.DeviceOtaForm;
import com.herui.ota.pojo.form.NoneFilterForm;
import com.herui.ota.service.DeviceOtaService;
import com.herui.ota.service.iml.BaseService;
import com.mlnx.common.annotations.NeedLogin;
import com.mlnx.common.entity.Response;
import com.mlnx.common.entity.ResponseData;
import com.mlnx.common.enums.BusinessType;
import com.mlnx.common.form.PageForm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.shan.spring.base.CurdBaseController;
import org.shan.spring.base.RdBaseController;
import org.shan.spring.base.UrdBaseController;
import org.shan.spring.base.annotations.SysLog;
import org.shan.spring.mybatis.service.ICurdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

@Api(value = ControllerNames.OTAName + "接口", tags = {ControllerNames.OTAName + "接口"})
@SysLog(title = ControllerNames.OTAName)
@RestController
@RequestMapping("/ota")
public class OTAController extends CurdBaseController<DeviceOta, DeviceOtaForm, DeviceOtaForm, DeviceOtaFilterForm> {
    @Autowired
    private DeviceOtaService service;

    @Override
    public ICurdService getService() {
        return service;
    }

    @Override
    public DeviceOta newInstance(Integer id) {
        DeviceOta soft = new DeviceOta();
        soft.setId(id);
        return soft;
    }

    @ApiOperation(
            value = "分页获取",
            notes = ""
    )
    @PostMapping({"/page"})
    public ResponseData<IPage> listPage(@Valid PageForm pageForm, DeviceOtaFilterForm ft) throws IllegalAccessException {
        return this.result(this.getService().page(pageForm, ft));
    }

    @ApiOperation("导出excel列表")
    @GetMapping("/excel")
    public void getMqttParamById(PageForm pageForm, DeviceOtaFilterForm filter, HttpServletResponse response) throws IllegalAccessException {
        BaseService baseService = (BaseService) service;
        baseService.pageExcel( pageForm, filter,response);
    }

    @NeedLogin
    @ApiOperation(
            value = "重置树状图",
            notes = ""
    )
    @PutMapping({"/resetTree"})
    public Response resetTree() {
        service.resetTree();
        return this.result();
    }
}
